package com.caocaog.market.controller;

import com.caocaog.market.annotation.IgnoreAuth;
import com.caocaog.market.data.transfer.service.MkSiteBasicService;
import com.caocaog.market.entity.ShopChannel;
import com.caocaog.market.service.IShopBasicService;
import com.caocaog.market.service.IShopChannelService;
import com.caocaog.market.vo.ShopVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequiredArgsConstructor
@Api(value = "shopApi", tags = "API店铺列表")
@RequestMapping("/api/shop")
public class ApiShopController {
    private static final String SURROUNDING = "周边服务类型店铺";
    private static final String INFO = "根据shopId获取店铺详情";
    @Autowired
    private IShopChannelService shopChannelService;
    @Autowired
    private IShopBasicService shopBasicService;
    @Autowired
    private MkSiteBasicService mkSiteBasicService;

    /**
     * 首页 频道
     * @param shopChannel 参数
     * @return 从首页中去查询出所有的一级频道
     */
    @IgnoreAuth
    @ApiOperation(value = "首页一级频道", notes = "首页一级频道")
    @GetMapping(value = "/channelList")
    public Result<?> channelList(ShopChannel shopChannel) {

        log.info("首页一级频道");
        return Result.OK(this.shopChannelService.shopChannelHomeDisplayList(shopChannel));
    }

    @IgnoreAuth
    @ApiOperation(value = "根据一级id查询二级信息", notes = "id:频道id必传")
    @GetMapping(value = "/getSecondaryLevelChannel")
    public Result<?> getSecondaryLevelChannel(@RequestParam String id, @RequestParam(required = false) String siteId) {
        log.info("获取二级分类");
        return Result.OK(shopChannelService.getSecondaryLevelChannel(id, siteId));
    }

    // 根据频道筛选 门店的距离显示排序
    @IgnoreAuth
    @AutoLog(value = "根据频道id筛选")
    @ApiOperation(value = "根据频道id筛选 门店的距离显示排序", notes = "返回店铺集合",response = ShopVo.class)
    @GetMapping(value = "/shopListByChannelId")
    public Result<?> shopListByChannelId(@RequestParam(required = false) String siteId,
                                         @RequestParam String id,
                                         @RequestParam String lat,
                                         @RequestParam String lng) {
        return shopBasicService.shopListByChannelId(siteId,id,lat,lng);
    }

    @ApiOperation(value = SURROUNDING, notes = "请传入经纬度来获取周边服务类型店铺")
    @GetMapping(value = "/surrounding")
    public Result<?> getSurroundingServeShop(@RequestParam String lat, @RequestParam String lng, @RequestParam(required = false) String siteId) {
        return Result.OK(shopBasicService.getSurroundingServeShop(lat, lng, siteId));
    }

    @AutoLog(value = "根据经纬度获取周边最近的分站")
    @ApiOperation(value = "根据经纬度获取周边最近的分站", notes = "根据经纬度获取周边最近的分站")
    @GetMapping(value = "/getSiteId")
    public Result<?> getSiteId(@RequestParam String lat, @RequestParam String lng) {
        return Result.OK(mkSiteBasicService.getSurroundingSiteIdByMap(lat, lng));
    }

    @ApiOperation(value = INFO, notes = INFO)
    @GetMapping(value = "/info")
    public Result<?> getShopInfo(@RequestParam String shopId, @RequestParam String lat, @RequestParam String lng) {
        return Result.OK(shopBasicService.getShopInfo(shopId, lat, lng));
    }

}
